﻿using Furion.DatabaseAccessor;
using Htx.Fur.Core.ContextLocators;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Htx.Fur.Core.Entities
{
    [Manual]
    [Table("Person")]
    [Comment("个人表")]
    public class Person : EntityBase<int, SqliteDbContextLocator>, IEntitySeedData<Person>, IEntityTypeBuilder<Person>
    {
        [MaxLength(64)]
        [Comment("姓名")]
        public string Name { get; set; }
        [Comment("编码")]
        public string Code { get; set; }
        //[Column(TypeName = "decimal(18,2)")]
        [Comment("年龄")]
        public int Age { get; set; }
        [Comment("地址")]
        public string Address { get; set; }

        public void Configure(EntityTypeBuilder<Person> entityBuilder, DbContext dbContext, Type dbContextLocator)
        {
            entityBuilder.ToSqlQuery(
                @"select * from dbo.person.2021-08-22
                  union all
                  select * from dbo.person.2021-09-22");
        }

        /// <summary>
        /// 种子
        /// </summary>
        /// <param name="content"></param>
        /// <param name="dbContextLocator"></param>
        /// <returns></returns>
        public IEnumerable<Person> HasData(DbContext content, Type dbContextLocator)
        {
            return new List<Person>
            {
                new Person{ Id = 1, Name = "孙小双", Code = "sunxiaoshuang", Age = 33, Address = "湖北省孝感市汉川市" },
                new Person{ Id = 2, Name = "华天晓", Code = "huatianxiao", Age = 23, Address = "湖北省武汉市东湖高新区" },
            };
        }
    }
}
